package util

import (
	"backend/Dao"
	"backend/Service/dbService"
	"backend/Service/minioService"
	"backend/Service/redisService"
	. "backend/config"
	"fmt"
)

func InitServer() {
	InitConfig()
	fmt.Println(Config)
	dbService.Init()
	minioService.Init()
	redisService.Init()

	//initMysql()
	//initMinio()

}

func initMysql() {
	err := dbService.DbConn.AutoMigrate(Dao.Chapter{},
		Dao.Class{},
		Dao.ContentsDiscussion{},
		Dao.Curriculum{},
		Dao.CurriculumSeries{},
		Dao.DataSpace{},
		Dao.Homework{},
		Dao.HomeworkFile{},
		Dao.RepContentDiscussion{},
		Dao.StuHomework{},
		Dao.Student{},
		Dao.StudentCurriculum{},
		Dao.Teacher{},
		Dao.TopicDiscussion{})
	if err != nil {
		fmt.Println("初始化mysql错误:", err.Error())
		return
	}
	count := int64(0)
	dbService.DbConn.Model(&Dao.Teacher{}).Count(&count)
	if count == 0 {
		dbService.DbConn.Create(&Dao.Teacher{
			Model:           Dao.GetModel(),
			TeacherName:     "马韬循",
			TeacherPwd:      "990812",
			TeacherUsername: "mataoxun",
			TeacherAva:      "",
		})
	}
}
func initMinio() {
	fmt.Println(minioService.MakeBucket("dataspace"))
	fmt.Println(minioService.MakeBucket("homework"))
	minioService.OpenPolicy("homework")
	minioService.OpenPolicy("dataspace")
}
